/**
 * @author Michael,Aug 15, 2012
 *
 */
package com.tm.util;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Michael
 *
 */
public class TestUtil {
	
	public static final ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"});
	
	public static Object getBean(String key){
		return context.getBean(key);
	}
	
	public static Object getBean(Class<?> classes){
		return context.getBean(classes);
	}
	
	public static String getRandomString(int count){
		return RandomStringUtils.randomAlphabetic(count);
	}
	
	public static Integer getRandomNumber(int count){
		if(count > 11) count = 11;
		return Integer.parseInt(RandomStringUtils.randomNumeric(count));
	}
	
	public static String getRandomEmail(){
		String start = "t_"+TestUtil.getRandomString(8);
		String dot = "@"+TestUtil.getRandomString(5)+".com";
		return (start+dot).toLowerCase();
	}
	
}
